package cn.zwx.activiti.example.conifig;

import springfox.documentation.service.Parameter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @projectName:store-billing
 * @see:cn.wywk.store.marketing.config
 * @author:zhangwenxue
 * @createTime:2021/5/13 14:30
 * @version:1.0
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Value("${spring.profiles.active}")
    private String profiles;

    @Bean
    public Docket createRestApi() {
        Boolean enable = profiles.equals("prod")?Boolean.FALSE:Boolean.TRUE;
        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<Parameter>();
        tokenPar.name("userName").description("用户姓名")
                .modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        pars.add(tokenPar.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(enable)
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.zwx.activiti.example.controller"))
                .paths(PathSelectors.any())
                .build().globalOperationParameters(pars);
        // http://192.168.0.108:8888/swagger-ui.html#/
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("工作流服务接口管理文档")
                .description("工作流服务接口管理文档")
                .termsOfServiceUrl("http://192.168.0.108:8888")
                .contact(new Contact("张文学","","zhangwenxue@wywk.cnm"))
                .version("1.0")
                .build();
    }

}
